package com.yunding.house.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunding.house.mapper.StaffMapper;


import com.yunding.house.pojo.Staff;
import com.yunding.house.service.StaffService;
import com.yunding.house.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author linyang
 * @since 2019-08-15
 */
@Service
public class StaffServiceImpl implements StaffService {
    @Autowired
    private StaffMapper staffMapper;

    @Override
    public void save(Staff staff) {
        staffMapper.insert(staff);
    }

    @Override
    public void del(long id) {
        staffMapper.deleteById(id);
    }

    @Override
    public void update(Staff staff) {
        staffMapper.updateById(staff);
    }

    @Override
    public List<Staff> findAll() {
        return staffMapper.selectList(null);
    }

    @Override
    public Staff selectone(long id) {
        return staffMapper.selectById(id);
    }

    @Override
    public PageResult search(int page, int size, Staff staff) {
        Page<Staff> staffPage=new Page<>(page,size);
        //条件对象
        QueryWrapper queryWrapper = new QueryWrapper(new Staff());
        //模糊查询name
        queryWrapper.like("staff_name", staff.getStaffName());
        IPage iPage = staffMapper.selectPage(staffPage, queryWrapper);
        return new PageResult(iPage.getTotal(), iPage.getRecords());
    }
}
